<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <title></title>
    </head>
    <?php
    session_start();
    print "<h1>Please enter the User's email</h1>";
    //the conference id from the URL
    $confid = $_GET['conference_id'];
    //the unique id in this page
    if (!isset($_SESSION['id'])) {
        $_SESSION['id'] = 0;
    }
    //call make_id function which send the email to the user
    if (isset($_POST['Send'])) {
        make_id($_POST['e_mail'], $confid);
    }

    //makes a unique id to the person organizer's sends email to
    function make_id($e_mail, $confid) {
        $con = mysql_connect("localhost", "root", "");
        if (!$con) {
            die('Could not connect:' . mysql_error());
        }
        mysql_select_db("mydb", $con);

        //unique id for the new user
        $_SESSION['id'] = $_SESSION['id'] + 1;
        //securing the id and adding the date to give it more privacy
        $key = md5($_SESSION['id'] . getdate());
        //check if the text field is empty
        if ($_POST['e_mail'] == NULL) {
            echo 'Please enter the required information';
        }
        //check if the entered email is a proper one or not
        else {
            $email = filter_var($e_mail, FILTER_SANITIZE_EMAIL);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                echo "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
            } else {
                //inserting the request in the Request_On_Subscribe table
                $query = "INSERT INTO Request_On_Subscribe(temp_id, request_email , conference_id)
                  VALUES ('$key','$email', '$confid')";

                mysql_query($query)
                        or die(mysql_error());
                //send the email to the non subscribed user

                $subject = 'Confo Request';
                $message = <<<EMAIL
The Confo site asks you to become a member in the review committe, If you are interested please check the following link: http://localhost:1234/ConfO/Non_subscribed_signup.php?id=$key


EMAIL;
                $from = 'mahico_92@hotmail.com';
                $headers = "From:" . $from;
                mail($e_mail, $subject, $message, $headers);
                echo 'The email is sent successfully';

                mysql_close($con);
            }
        }
    }
    ?>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <form method="post" Action =""/>
    <td>
        <input type ="text" name ="e_mail" maxlength ="30"/>
    </td>
    <td>
        <input type ="submit" name ="Send" value ="Send" />
    </td>


</body>
</html>
